﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Services_ServiceGuest : System.Web.UI.Page
{ 
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblPath.Text = f.getModuleidAdd(Request.QueryString["moduid"].ToString());
        if (!IsPostBack)
        {
            hfxs.Value = Request.QueryString["moduid"].ToString();
            StaffName.Text = Request.QueryString["StaffName"];
            GuestName.Text = Request.QueryString["GuestName"];
            Guesttel.Text = Request.QueryString["Guesttel"];
            HidWareid.Value = getWareId();
            initData();
        }
    }


    private void initData()
    {
        string search = "";
        string sql = "select * from(select a.*,(select StaffName from CS_Staff where StaffId=a.maintmen) as StaffName from CS_Mailadd a) TblMailadd  where 1=1";

        if (!string.IsNullOrEmpty(Request.QueryString["StaffName"]))//订单号
        {
            search += "&StaffName=" + Request.QueryString["StaffName"].Trim();
            sql += " and StaffName like '%" + Request.QueryString["StaffName"].Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["GuestName"]))//客户名称
        {
            search += "&GuestName=" + Request.QueryString["GuestName"].Trim();
            sql += " and GuestName like '%" + Request.QueryString["GuestName"].Trim() + "%'";
        }
        if (!string.IsNullOrEmpty(Request.QueryString["Guesttel"]))//型号编号
        {
            search += "&Guesttel=" + Request.QueryString["Guesttel"].Trim();
            sql += " and Guesttel='" + Request.QueryString["Guesttel"].Trim() + "'";
        }
        sql += " order by Maintaddid desc";
        //Response.Write(sql);
        //Response.End();
        PageNavigator1.Url = "../Services/selectGuestwc.aspx.aspx?moduid=" + hfxs.Value + search;
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;


    }
    private string getWareId()
    {
        ZSql zs = new ZSql();
        string sql = "select WarehouseId from UserInfo where userid=" + Request.Cookies["user"].Values["id"];
        zs.Open(sql);

        zs.Close();
        return zs.m_table.Rows[0]["WarehouseId"].ToString();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = "";
        if (!string.IsNullOrEmpty(StaffName.Text.Trim()))//订单号
        {
            search += "&StaffName=" + Common.FormatParameter(StaffName.Text.Trim());
        }
        if (!string.IsNullOrEmpty(GuestName.Text.Trim()))//客户名称
        {
            search += "&GuestName=" + Common.FormatParameter(GuestName.Text).Trim();
        }
        if (!string.IsNullOrEmpty(Guesttel.Text))//型号编号
        {
            search += "&Guesttel=" + Common.FormatParameter(Guesttel.Text.Trim());
        }
        PageNavigator1.Url = "../Services/selectGuestwc.aspx?moduid=" + hfxs.Value + search;
        Response.Redirect("selectGuestwc.aspx?moduid=" + hfxs.Value + search);
    }


    protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)//在邦定数据
    {
        //f.checkLevels(Request.Cookies["user"].Values["roleid"], hfxs.Value, 4, GvDataType, btndel, btnallflag, btnAdd);//权限string lyyybz = "";
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string StrReturn = DataBinder.Eval(e.Row.DataItem, "Guestname").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "Guestname").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "Guesttel").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "Guestaddress").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "comitype").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "comidband").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "comidSpe").ToString() + "," + DataBinder.Eval(e.Row.DataItem, "MaintDate").ToString();
            e.Row.Attributes.Add("ondblclick", "selectInfo('" + StrReturn + "')");
            //e.Row.Cells[11].Attributes.Add("onmouseout", "Remove()");

        }    
        
    }


}
